package org.yxs.excel.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;
import org.yxs.excel.entity.Product;

import java.util.List;

@Component
@Mapper
public interface ProductMapper {
    @Insert("insert into product(id,name) values(#{id},#{name})")
    int add(Product product);

    @Update("update product set name=#{name} where id=#{id}")
    int update(Product product);

    @Delete("delete from product where id=#{id}")
    int deleteById(Integer id);

    @Select("select * from product where id=#{id}")
    @Results(id = "product", value = {
            @Result(property = "id", column = "id", javaType = Integer.class),
            @Result(property = "name", column = "name", javaType = String.class)
    })
    Product queryProductById(Integer id);

    @Select("select * from product where id > #{id} order by id asc limit #{size}")
    @Results(id = "productResult", value = {
            @Result(property = "id", column = "id", javaType = Integer.class),
            @Result(property = "name", column = "name", javaType = String.class)
    })
    List<Product> select(Integer id, Integer size);


    int addList(List<Product> products);

}